;(function($){
	$(window).resize(function(event) {
		$('.fc_list li').each(function(index,item){
			$(item).find('.img_wrap').each(function(ind,itm){
				$(itm).css({marginTop: -$(itm).height()/2});
			});
		});
		layoutFn();
	});
	
	(function(){
		var manifest = $("#main_content img").toArray();
		var handleProgress = function(e) {
			var p = Math.round(e.progress * 100);
			$('.loading_page>li').each(function(index,item){
				if(p<(index+1)*25){
					$(item).show().siblings().hide();
					return false;
				};
			});
			$('#loading .loading_txt span').text(p + '%');
		} //加载时回调
		var handleComplete = function(e) {
			$('#loading').remove();
			$('#main_content').show();
			$(window).resize();
		} //加载完毕回调
		if(manifest.length>0){
			var preload = new createjs.LoadQueue(false);//false会缓存文件，二次点击不会重新请求，true每次点击都会重新请求文件
			preload.on("progress", handleProgress, this);
			preload.on("complete", handleComplete, this);
			preload.loadManifest(manifest);
		}else{
			handleComplete();
		};
	})();
	
	function layoutFn(){
		var viewculm = $('.viewboard .view_culm'),
			vw = viewculm.parent().width(),
			normal_vw = '25%',
			max_vw = '50%', //vw/2
			min_vw = 1/6, //max_vw/3
			st,
			ww = $(window).width(),
			canvascale = ww*0.4/800,
			xx = 800-ww*0.4;
		TweenLite.set($("#canvas_1"), {x:-xx/2,transformOrign:'0% 0%', scale:canvascale});
		function eventFn(item,event){
			st = setTimeout(function(){

				$('.canvas_wrap').each(function(ind,itm){
					if(ind == $(item).index()){
						TweenLite.to($(itm).find('canvas'), 0.5, {marginLeft:'0%'});
					}else{
						TweenLite.to($(itm).find('canvas'), 0.5, {marginLeft:'60%'});
					};
				});
				
				var current = TweenLite.to($(item), 0.5, {width:max_vw});
				current.eventCallback("onComplete", function(e){
					$(item).css("cursor", "default").addClass('active');
				},[]);
				var paused = TweenLite.to($(item).siblings('.view_culm'), 0.5, {width:min_vw*100+'%'});
				paused.eventCallback("onComplete", function(e){
					$(item).css("cursor", "pointer").removeClass('active');
				},[]);

				// $(item).stop().animate({
				// 	width: max_vw-1
				// }, {duration: 500, easing: 'swing',complete: function(){

				// }}).css("cursor", "default").addClass('active');

				$(item).find('.doll_icon_wrap').fadeOut('200', function() {
					
				});

				// $(item).siblings('.view_culm').stop().animate({
				// 	width: min_vw
				// }, {duration: 500, easing: 'swing',complete: function(){

				// }}).css("cursor", "pointer").removeClass('active');

				// $(item).siblings('.view_culm.d4').stop().animate({
				// 	width: min_vw
				// }, {duration: 500, easing: 'easeOutBack',complete: function(){
				// 	$(this).width(min_vw);
				// }});
				$(item).siblings('.view_culm').find('.doll_icon_wrap').fadeIn('500', function() {});
			},500);
		};
		viewculm.each(function(index,item){
			$(this).on('click',function(){
				if($(this).hasClass('active')){
					//console.log(1)
				};
			});
			$(this).mouseover(function(event){
				eventFn(item,event);
			});
			$(this).mouseleave(function(event) {
				clearTimeout(st);
			});
		});
	};
	$('#menu').each(function(index,item){
		var openBL = false;
		$(this).find('.menu_tigger').on('click',function(){
			if(!openBL){
				$(item).stop().animate({
						left: 0
				}, {duration: 500, easing: 'easeOutQuart',complete: function(){
					openBL = true;
				}}).addClass("open");
			}else{
				$(item).stop().animate({
						left: '-15%'
				}, {duration: 500, easing: 'easeInQuart',complete: function(){
					openBL = false;
				}}).removeClass("open");
			};
			
		});
		$(this).find('.menu_list li').each(function(){
			$(this).on('mouseover',function(){
				$(this).addClass('active').siblings('li').removeClass('active');
			});
			$(this).on('mouseleave',function(){
				$(this).removeClass('active');
			});
		});
	});
	function canvasModel(){
		this.init();
	};
	canvasModel.prototype = {
		loadCanvas: function(){
			var sf = this;
			function addEvent(index,item,canvas,images,manifest,loader){
				var self = this;
					var images = images||{};
				console.log(manifest,loader);
				loader.addEventListener("fileload", handleFileLoad);
				loader.addEventListener("complete", handleComplete);
				if(index == 1){
					//console.log(this.manifest)
				}
				
				loader.loadManifest(manifest);
				function handleFileLoad(evt) {
					if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
					//console.log(self.images)
					console.log(images)
				};
				function handleComplete() {
					//console.log(lib['canvas'+self.index])
					exportRoot = new lib['canvas'+index]();
					stage = new createjs.Stage(canvas);
					stage.addChild(exportRoot);
					stage.update();
					createjs.Ticker.setFPS(30);
					createjs.Ticker.addEventListener("tick", stage);
					//exportRoot.onStop();
					console.log(1)
				};
				$(self.canvas).on('click',function(event) {
					//console.log(exportRoot)
					exportRoot.onPlay();
				});
			};
			this.canvasArr.each(function(index,item){
				if(index<1){
					var canvas = item;
					var manifest = sf.manifest[index];
					var loader = new createjs.LoadQueue(false);
					addEvent(index,item,canvas,images,manifest,loader); 
				}
				
			});
		},
		init: function(){
			this.canvasArr = $('.canvasView');
			this.imageObj = this.imageObj||{};
			this.manifest = [
				[
					{src:"assets/images/lib0_img_000001.png", id:"lib0_img_000001"},
					{src:"assets/images/lib0_img_000002.png", id:"lib0_img_000002"}
				],
				[
					{src:"assets/images/lib1_img_000001.png", id:"lib1_img_000001"},
					{src:"assets/images/lib1_img_000002.png", id:"lib1_img_000002"}
				],
				[
					{src:"assets/images/lib2_img_000001.png", id:"lib2_img_000001"},
					{src:"assets/images/lib2_img_000002.png", id:"lib2_img_000002"}
				],
				[
					{src:"assets/images/lib3_img_000001.png", id:"lib3_img_000001"},
					{src:"assets/images/lib3_img_000002.png", id:"lib3_img_000002"}
				]
			];
			this.loadCanvas();
		}
	};
	new canvasModel();
	function loadCanvas(){
		canvas = document.getElementById("canvas_1");
		images = images||{};

		var manifest = [
			{src:"assets/images/lib0_img_000001.png", id:"lib0_img_000001"},
			{src:"assets/images/lib0_img_000002.png", id:"lib0_img_000002"}
		];

		var loader = new createjs.LoadQueue(false);
		loader.addEventListener("fileload", handleFileLoad);
		loader.addEventListener("complete", handleComplete);
		loader.loadManifest(manifest);
	};
	function handleFileLoad(evt) {
		if (evt.item.type == "image") { images[evt.item.id] = evt.result; }
		console.log(evt)
	}
	function handleComplete() {
		exportRoot = new lib.canvas0();

		stage = new createjs.Stage(canvas);
		stage.addChild(exportRoot);
		stage.update();

		createjs.Ticker.setFPS(30);
		createjs.Ticker.addEventListener("tick", stage);
	}
	//loadCanvas();




	
})(jQuery);